package visitor;

import java.util.Iterator;

public class Main {
    public static void main(String[] args) {
// 1.
        Directory rootDir = new Directory("root");
//2.
        Directory binDir = new Directory("bin");
        Directory usrDir = new Directory("usr");
        File tmp = new File("tmp", 222);
        File html=new File("hahah.html",23323);
        usrDir.add(html);
        rootDir.add(binDir);
        rootDir.add(usrDir);
        rootDir.add(tmp);
        rootDir.accept(new ListVisitor());
// 3.
        File vi = new File("vi", 333);
        File latex = new File("latex", 444);
        binDir.add(vi);
        binDir.add(latex);
        Directory yukiDir = new Directory("yuki");
        Directory hanakoDir = new Directory("hanako");
        Directory tomuraDir = new Directory("tomura");
        usrDir.add(yukiDir);
        usrDir.add(hanakoDir);
        usrDir.add(tomuraDir);

//4.
        File diary = new File("diary.html", 100);
        File composite = new File("Composite.java", 500);
        yukiDir.add(diary);
        yukiDir.add(composite);
        File game = new File("game.doc", 600);
        File iunk = new File("iunk.mail", 700);
        tomuraDir.add(game);
        tomuraDir.add(iunk);
        rootDir.accept(new ListVisitor());


        System.out.println("=====自定义visitor测试");
        FileFindVisitor fileFindVisitor = new FileFindVisitor();
        rootDir.accept(fileFindVisitor);
        for (File file : fileFindVisitor.getFoundFiles()) {
            System.out.println(file.getName());
        }
    }

}
